/*
 * Copyright (c) 2016. For Intelligent Group.
 */

package com.intelligent.ispc.core.dto;

import com.intelligent.ispc.common.dto.AbstractValueObject;
import com.intelligent.ispc.common.mapper.BeanMapper;
import com.intelligent.ispc.core.entity.ToleranceItem;
import com.intelligent.ispc.core.entity.ToleranceScheme;

/**
 * Created by Peter on 2016/8/22.
 */
public class ToleranceItemDto extends AbstractValueObject {

    private Long id;
    private String code;
    private String componentName;
    private String loopType;
    private String coefficient;
    private String nominalSize;
    private String unilateralTolerance;
    private String ldl;
    private String udl;
    private String mean;
    private String sigma;

    private double usl;
    private double lsl;

    private Long schemeId;
    private Long projectId;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getComponentName() { return componentName; }

    public void setComponentName(String componentName) { this.componentName = componentName; }

    public String getLoopType() {
        return loopType;
    }

    public void setLoopType(String loopType) {
        this.loopType = loopType;
    }

    public String getCoefficient() {
        return coefficient;
    }

    public void setCoefficient(String coefficient) {
        this.coefficient = coefficient;
    }

    public String getNominalSize() { return nominalSize; }

    public void setNominalSize(String nominalSize) { this.nominalSize = nominalSize; }

    public String getUnilateralTolerance() {
        return unilateralTolerance;
    }

    public void setUnilateralTolerance(String unilateralTolerance) {
        this.unilateralTolerance = unilateralTolerance;
    }

    public String getLdl() {
        return ldl;
    }

    public void setLdl(String ldl) {
        this.ldl = ldl;
    }

    public String getUdl() {
        return udl;
    }

    public void setUdl(String udl) {
        this.udl = udl;
    }

    public String getMean() { return mean; }

    public void setMean(String mean) { this.mean = mean; }

    public String getSigma() {
//        if (this.sigma == null) return null;
//        String s = sigma.substring(0, sigma.length()-1);
//        if ("".equals(s)) s = "1";
//        Double sg = (Double.parseDouble(udl) - Double.parseDouble(ldl))/(Double.parseDouble(s));
//        return sg.toString();
        return sigma;
    }

    public void setSigma(String sigma) { this.sigma = sigma; }

    public double getUsl() {
        return usl;
    }

    public void setUsl(double usl) {
        this.usl = usl;
    }

    public double getLsl() {
        return lsl;
    }

    public void setLsl(double lsl) {
        this.lsl = lsl;
    }

    public Long getSchemeId() {
        return schemeId;
    }

    public void setSchemeId(Long schemeId) {
        this.schemeId = schemeId;
    }

    public Long getProjectId() {
        return projectId;
    }

    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }

    public static void dtoToEntity(ToleranceItemDto dto, ToleranceItem entity) {
        if(dto.getSchemeId() != null) {
            ToleranceScheme toleranceScheme = new ToleranceScheme();
            toleranceScheme.setId(dto.getSchemeId());
            entity.setToleranceScheme(toleranceScheme);
        }
        BeanMapper.copy(dto, entity);
    }
}
